﻿using Inovout.Web.Controllers;
using System.Web.Mvc;
using Inovout.Security;
using System.Web.Security;

namespace Inovout.Portal.WebSite.Controllers
{
    public class AccountController : BaseController
    {
        private readonly IUserService userService;

        public AccountController(IUserService userService)
        {
            this.userService = userService;
        }
        [HttpGet,AllowAnonymous]
        public ActionResult SignIn()
        {
            ViewBag.Title = "登录";
            return View();
        }

        [HttpPost,AllowAnonymous]
        public ActionResult SignIn(IAuthenticatedUser user, string returnUrl)
        {
            if (userService.Authenticate(user))
            {
                 FormsAuthentication.SetAuthCookie(user.Name,false);
                if (!string.IsNullOrEmpty(returnUrl))
                {
                    return Redirect(returnUrl);
                }
            }
            return View();
        }
    }
}